package com.example.service;


import cn.hutool.core.util.ObjectUtil;
import com.example.entity.Help;
import com.example.mapper.HelpMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 救援信息业务层
 */
@Service
public class HelpService {
    @Resource
    private HelpMapper helpMapper;

    public void add(Help help) {
        //进行逻辑处理
            helpMapper.insert(help);
        }

    public PageInfo<Help> selectPage(Help help, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Help> list;
        if (ObjectUtil.isNotEmpty(help.getVolunteerId())) {
            Integer volunteerId = help.getVolunteerId();
            // 表示当前登录的是教师这个角色
            if (ObjectUtil.isNotEmpty(help.getName())) {
                list = helpMapper.selectByNameAndVolunteerId(help.getName(), volunteerId);
            } else {
                list = helpMapper.selectAllByVolunteerId(volunteerId);
            }
        } else {
            if (ObjectUtil.isNotEmpty(help.getName())) {
                list = helpMapper.selectByName(help.getName());
            } else {
                list = helpMapper.selectAll();
            }
        }

        return PageInfo.of(list);



    }

    public void updateById(Help help) {
        helpMapper.updateById(help);
    }

    public void deleteById(Integer id) {
        helpMapper.deleteById(id);
    }

    public List<Help> selectAll() {
        return helpMapper.selectAll();
    }
}

